﻿using MaterialDesignThemes.Wpf;
using System.Windows;
using YFurion.Localization;

namespace UpperComputer.WPF.Entry.Common.Extensions
{
    public static class MessageBoxExtensions
    {
        #region 显示消息
        public static void ShowInfoMessage(this Snackbar snackbar, string content)
        {
            snackbar.ShowMessage(content, MessageBoxImage.Information);
        }

        public static void ShowWarningMessage(this Snackbar snackbar, string content)
        {
            snackbar.ShowMessage(content, MessageBoxImage.Warning);
        }

        public static void ShowErrorMessage(this Snackbar snackbar, string content)
        {
            snackbar.ShowMessage(content, MessageBoxImage.Error);
        }

        private static void ShowMessage(this Snackbar snackbar, string content, MessageBoxImage icon)
        {
            snackbar.MessageQueue?.Clear();
            MessageControl messageControl = new MessageControl(Furion.App.GetService<ILocalizationManager>()[content], icon);
            snackbar.MessageQueue?.Enqueue(messageControl, "❌", (s) => s.MessageQueue.Clear(), snackbar);
        }
        #endregion

        #region 显示消息盒
        public static void ShowInfoBox(this object obj, string text)
        {
            obj.ShowBox(text, "提示", MessageBoxImage.Information);
        }

        public static void ShowWarningBox(this object obj, string text)
        {
            obj.ShowBox(text, "警告", MessageBoxImage.Warning);
        }

        public static void ShowErrorBox(this object obj, string text)
        {
            obj.ShowBox(text, "错误", MessageBoxImage.Error);
        }

        public static MessageBoxResult ShowQuestionBox(this object obj, string text)
        {
            return obj.ShowBox(text, "询问", MessageBoxImage.Question, true);
        }

        private static MessageBoxResult ShowBox(this object obj, string text, string caption, MessageBoxImage icon, bool isShowCancel = false)
        {
            ILocalizationManager lang = Furion.App.GetService<ILocalizationManager>();
            ConfirmDialog dialog = new ConfirmDialog(lang[text], lang[caption], icon, isShowCancel);
            bool rs = dialog.ShowDialog().Value;
            return rs ? MessageBoxResult.OK : MessageBoxResult.Cancel;
        }
        #endregion
    }
}
